package org.acghub.mtdb.util;

/**
 * @author zhouhe
 */
public final class StringUtil {

    public static final String EMPTY = "";
    public static final String TAB = "\t";


    public static String tab(int x) {
        return repeat(TAB, x);
    }

    public static String concat(String... values) {
        StringBuilder sb = new StringBuilder();
        for (String value : values) {
            sb.append(value);
        }
        return sb.toString();
    }

    public static String repeat(String s, int x) {
        if (isEmpty(s)) {
            return EMPTY;
        }
        return s.repeat(Math.max(1, x));
    }

    public static String trim(String value) {
        return value == null ? null : value.trim();
    }

    public static String upperFirstChar(String value) {
        return value.substring(0, 1).toUpperCase() + value.substring(1);
    }

    public static String quote(String value) {
        return "\"" + value + "\"";
    }

    public static boolean isEmpty(CharSequence type) {
        return type == null || type.isEmpty();
    }

    public static boolean isNotEmpty(CharSequence type) {
        return !isEmpty(type);
    }

    public static String getPrintComment(String comment) {
        if (StringUtil.isEmpty(comment)) {
            return StringUtil.EMPTY;
        }
        if (!comment.startsWith("//")) {
            return "// " + comment;
        }
        return comment;
    }

    public static String checkValueSuffix(String value, String f) {
        if (value.endsWith(f.toLowerCase()) || value.endsWith(f.toUpperCase())) {
            return value;
        }
        return value += f.toUpperCase();
    }
}
